<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ajax简单封装</title>
</head>
<body>
    <ul>
        
    </ul>
    <!-- 引入ajax.js文件 -->
    <script src="./ajax.js"></script>
    <script>
        ajax('http://localhost:3014//prodcuts/A?price=2').then(
            // value是product对象组成的数组
        value =>{
            console.log(value);
            //根据列表数据生成多个li标签的字符串
            const lis = value.reduce((pre,p)=>pre+`<li>${p.id}--${p.name}--${p.price}</li>`,'')

            // 第一步 pre = '' , '<li>2--'
            // 插入到ul
            const ul = document.querySelector('ul')

            ul.innerHTML = lis
        }
        ),error=>{
            alert(error.message)
        }
                
                
                
    </script>
</body>
</html>